package com.demo;
import java.util.Queue;
import java.util.Stack;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

class Solution1 {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i=0;i<s.length();i++) {
            char c = s.charAt(i);
            if (c == '(' || c == '{' || c == '[') {
                stack.push(c);
            } else {
                if (stack.isEmpty())
                    return false;

                char topChar = stack.pop();
                if (c == ')' && topChar != '(')
                    return false;
                if (c == ']' && topChar != '[')
                    return false;
                if (c == '}' && topChar != '{')
                    return false;
            }

        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1().isValid("{([])}"));
        System.out.println( new Solution1().isValid("{[)}"));
        Queue<Integer> queue=new ArrayBlockingQueue<Integer>(10);

    }
}